package com.sumainfor.zuul.controller;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.zuul.dao.Feign.MessageSetMapper;
import com.sumainfor.zuul.service.impl.Feign.MessageSetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 系统消息通知
 * <p>
 *
 * @author: zhoucong
 * @create: 2019-04-10 19:47
 **/
@Controller
@RequestMapping("/provider/message")
public class MessageSetController {

    @Autowired
    MessageSetService messageSetService;

    @Autowired
    MessageSetMapper messageSetMapper;

    /**
    * <p>
    * 获取系统消息列表
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @PostMapping("/getMessageList")
    public JsonResult getMessageList(@RequestParam Map<String, Object> params, Pager pager) {
        JsonResult result = new JsonResult();
        pager.setPageno(Integer.parseInt(params.get("pageno").toString()));
        pager.setPagesize(Integer.parseInt(params.get("pagesize").toString()));
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        if(!FieldCheckUtil.isMapFieldNotNull(params ,new String[]{"MeType"})){
            return  result.putFailed("服务器繁忙...");
        }
        Integer cout = messageSetMapper.getMessageListCount(params);
        if (cout == 0) {
            return pageUtils.getJsonResult(new ArrayList<Map<String, Object>>(), params, cout);
        }
        System.out.println("params"+params);
        List<Map<String, Object>> getMessageList = messageSetService.getMessageList(params);

        return pageUtils.getJsonResult(getMessageList, params, cout);

    }
}